<%--@elvariable id="typeName" type="java.lang"--%>
<%--@elvariable id="typeValue" type="java.lang"--%>
<%--
  Created by IntelliJ IDEA.
  User: gaoyang
  Date: 14-4-29
  Time: 下午4:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../includes/common.jsp" %>
    <title>分类值列表</title>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline" action="">
        <label for="typeValue">分类值</label>
        <input type="text" name="typeValue" id="typeValue" value=""/>
        <a class="btn btn-primary" onclick="query()">查询</a>
        <a class="btn btn-primary" onclick="addTypeValue()">新增</a>
        <a class="btn btn-primary" onclick="back()">返回</a>
    </form>
    <table id="dataTable"></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%"
                id="contentList"
                name="contentList"
                marginheight="0"
                marginwidth="0"
                frameborder="0" src=""
                allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function query() {
        listOption.url = basePath + "classify/listAllTypeValues";
        listOption.data = "typeValue=" + $("#typeValue").val().trim() + "&typeName=${typeName}" ;
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function back() {
        location.href = basePath + "classify/listAllType";
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "分类值",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'typeName', title: '分类名称', sortable: true, align: 'center', width: 200},
                     {field: 'typeValue', title: '分类值', align: 'center', width: 100},
                    {field: 'operate', title: '操作', align: 'center', width: 200 }
                ]
            ],
            sortName: "",
            sortOrder: "asc",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "typeValue":
                sortColumn = "type_value";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }

    function queryFormat(temp) {
        for (var i in temp) {
            temp[i].operate = "<a onclick='editTypeValues(" + temp[i].id + ",\"" + temp[i].typeValue + "\")'>编辑</a>&nbsp;&nbsp;"
                    + "<a onclick='delTypeValues(" + temp[i].id + ")'>删除</a>&nbsp;&nbsp;";
        }
        return temp;
    }

    function addTypeValue() {
        var path = basePath + "classify/addTypeValuesDo?typeName=${typeName}";
        $("#contentList").attr("src", path);
        $('#dataEdit').dialog({
            title: '新增',
            height: 400,
            width: 600
        }).dialog('open');
    }

    function editTypeValues(id, typeValue) {
        var path = basePath + "classify/editTypeValuesDo?TypeName=${typeName}&id=" + id + "&typeValue=" + typeValue;
        $("#contentList").attr("src", path);
        $('#dataEdit').dialog({
            title: '编辑',
            height: 400,
            width: 600
        }).dialog('open');
    }

    function delTypeValues(id) {
        $.messager.confirm("提示", "确认删除？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "classify/delTypeValue?typeName=${typeName}" + "&id=" + id,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "删除成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }

    $(function () {
        initDataGrid();
        query();
    })
</script>